package m202401.d05;

import java.util.Stack;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/1/5 09:18
 */
//71. 简化路径
public class Q71 {


    public String simplifyPath(String path) {
        String[] split = path.split("/");
        Stack<String> stack = new Stack<>();
        for (String s : split) {
            if (s == null || s.trim().equals("") || s.equals(".")) {
                continue;
            }
            if (s.equals("..")) {
                if (!stack.isEmpty()) {
                    stack.pop();
                }
                continue;
            }
            stack.push(s);
        }
        return "/" + String.join("/", stack);
    }
}
